<?php
// +----------------------------------------------------------------
// | LeisoonCMF V5.0
// +----------------------------------------------------------------
// | Copyright (c) 2016 http://www.leisoon.com All rights reserved.
// +----------------------------------------------------------------
// | Author: websky <web88@qq.com>
// +----------------------------------------------------------------

namespace app\common\controller;
/**
 * Upload控制器
 */
class KdApi
{
       const EBusinessID = "1653518";        //电商ID
       const AppKey = "4f16260e-09bc-4e5a-9543-b4ed95b2cf3d";         //电商加密私钥，快递鸟提供，注意保管，不要泄漏
       const ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";         //正式接口Url
    //物流跟踪接口   快递单号，订单号，快递公司代码
      public function orderTraces($kdNumber,$kd='EMS',$orderNumber=""){
          if(!$orderNumber)
              $orderNumber = uniqid();
          $requestData = json_encode([
              'OrderCode' => $orderNumber,
              'ShipperCode' => $kd,
              'LogisticCode'=> $kdNumber,
              "Callback" => 'http://myshop.wfdingrui.com/api/order/express_back'
          ]);
          $datas = array(
              'EBusinessID' => self::EBusinessID,
              'RequestType' => '1008',
              'RequestData' => urlencode($requestData) ,
              'DataType' => '2',
          );
          $datas['DataSign'] = encryptKdApi($requestData, self::AppKey);
          $result=sendPost(self::ReqURL, $datas);
          //根据公司业务处理返回的信息......
          return $result;
      }
      //即时查询
      public function orderSearch($kdNumber,$kd='EMS',$orderNumber=""){
          if(!$orderNumber)
              $orderNumber = uniqid();
          $requestData = json_encode([
              'OrderCode' => $orderNumber,
              'ShipperCode' => $kd,
              'LogisticCode'=> $kdNumber
          ]);
          $datas = array(
              'EBusinessID' => self::EBusinessID,
              'RequestType' => '1002',
              'RequestData' => urlencode($requestData) ,
              'DataType' => '2',
          );
          $datas['DataSign'] = encryptKdApi($requestData, self::AppKey);
          $result=sendPost(self::ReqURL, $datas);
          //根据公司业务处理返回的信息......
          return $result;
      }
}